package com.二叉树中和为某一值的路径;

import java.util.ArrayList;
import java.util.HashMap;

public class Solution {
    ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
    public ArrayList<ArrayList<Integer>> FindPath(TreeNode root,int target) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        FindPathCore(root,target,list);
        return result;
        
    }
    public void FindPathCore(TreeNode root,int target,ArrayList<Integer> list){
        if(root==null)return;
        target=target-root.val;
        list.add(root.val);
        if(target==0&&root.left==null&&root.right==null){
            result.add(list);
        }
        FindPathCore(root.left,target,list);
        FindPathCore(root.right,target,list);
        list.remove(list.size()-1);
        return;
    }
}
